﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Code4WP7SDK;
using System.Collections.ObjectModel;

namespace LuWeibo.ViewModels
{
    public class SkinsViewModel : BaseModel
    {
        #region Fields
        private ObservableCollection<SolidColorBrush> _skinBrushes;
        private ICommand _changeSkinCommand;
        private Brush _selectedBrush; //选中的皮肤
        #endregion

        #region Properties
        public ObservableCollection<SolidColorBrush> SkinBrushes
        {
            get
            {
                if (this._skinBrushes == null)
                {
                    this._skinBrushes = new ObservableCollection<SolidColorBrush> 
                    {
                        new SolidColorBrush(Colors.Red),
                        new SolidColorBrush(Colors.Black),
                        new SolidColorBrush(Colors.Green),
                        new SolidColorBrush(Colors.Blue)
                    };
                }
                return _skinBrushes;
            }
            set
            {
                _skinBrushes = value;
                this.NotifyPropertyChanged(p => p.SkinBrushes);
            }
        }

        public Brush SelectedBrush
        {
            get { return _selectedBrush; }
            set
            {
                _selectedBrush = value;
                this.NotifyPropertyChanged(p => p.SelectedBrush);
            }
        }
        #endregion

        #region Command
        public ICommand ChangeSkinCommand
        {
            get
            {
                if (this._changeSkinCommand == null)
                {
                    this._changeSkinCommand = new BaseCommand<SolidColorBrush>(ChangedSkinExecute);
                }
                return _changeSkinCommand;
            }
        }
        #endregion

        #region Method
        public void ChangedSkinExecute(SolidColorBrush selectedBrush)
        {
            if (selectedBrush != null)
            {
                //改变颜色
                if (selectedBrush.Color == Colors.Red)
                {
                    Theme.TurnRed();
                }
                else if (selectedBrush.Color == Colors.Green)
                {
                    Theme.TurnGreen();
                }
                else if (selectedBrush.Color == Colors.Blue)
                {
                    Theme.TurnBlue();
                }
                else if (selectedBrush.Color == Colors.Black)
                {
                    Theme.TurnBlack();
                }
                selectedBrush = null;
            }
        }
        #endregion
    }
}
